﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>LostCardMain</title>
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <link href="../../Content/Themes/blue2/css.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .LostCardShowTable{ margin-top:1px; width:100%; margin-left:auto; margin-right:auto; overflow:scroll;}
        .showLostOrStop th, td{ word-break:keep-all; white-space:nowrap;  border:1px black solid ; padding:3px;  }
        .showLostOrStip {border-color:#1C1C1C; height: 100%; width:100%;overflow:scroll;text-align:center; border-collapse:collapse; border-spacing:0;}
         .fieldCss{ border: solid 1px #C6E2FF;width: 98%;padding: 10px 0px 10px 10px;}
         .pager{ margin-left:30%;  padding-top:20px;}
    </style>
</head> 
<body class="main">
    <div class="AllWebTopDiv">
        <div class="path">
             <div class="nav">
               <a href="#">挂失办理</a>
             </div>
        </div>
        <div class="content">
            <fieldset class="fieldCss">
                        <legend>会员信息</legend>
                        <form>
                        <label>
                            会员编号：</label><%:Html.TextBox("memberId", null, new { @readonly = "readonly" })%>  
                        <label>
                            现有积分：</label><%:Html.TextBox("point", null, new { @readonly="readonly"})%>
                          <input  type="button" class="button2" value="挂失" onclick="lostCard(1);"/>
                           <input  type="button" class="button2" value="换卡" onclick="exchangeCard()"/>
                           <input  type="button" class="button2" value="关闭" onclick="closeWindows();"/>
                        <br />
                        <br />
                        <label>
                           姓&nbsp;&nbsp;&nbsp;名：</label><%:Html.TextBox("memberName", null, new { @readonly = "readonly" })%>
                        <label>
                            身份证号：</label><%:Html.TextBox("IDnumber", null, new { @readonly = "readonly" })%>
                            <input  type="button" class="button2" value="停用" onclick="lostCard(2);"/>
                            <input  type="button" class="button2" value="恢复正常" onclick="lostCard(0);"/>
                            <input  type="button" class="button2" value="寻卡"/>
                            
                            <br /><br />
                            <label>现有余额：</label><%:Html.TextBox("balance", null, new { @readonly = "readonly" })%>
                            
                            </form>
                    </fieldset>
                    <br /><br />
                     <label>挂失或停用的会员列表:</label>
                    <br />
                    <div class="LostCardShowTable">
                     <table class="showLostOrStop">
                     
                     </table>
                       <div class="pager">
                           <input  type="button" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.color='black';this.style.fontWeight='normal'" onclick="newPage('首页')"style="cursor:pointer"  value="首页" class="button"/>
                            <input type="button" value="上一页" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.color='black';this.style.fontWeight='normal'" onclick="newPage('上一页')"style="cursor:pointer" class="button"/>
                            <input type="button" value="下一页" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.color='black';this.style.fontWeight='normal'" onclick="newPage('下一页')"style="cursor:pointer" class="button"/>
                            <input type="button" value="末页" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.color='black';this.style.fontWeight='normal'" onclick="newPage('末页')"style="cursor:pointer" class="button"/>
      
       　                    共 <label id="maxPage">1</label> 页 第 <label id="CurrentPage">1</label> 页
                       </div>
                     <p>
                     <object classid="clsid:2323E9E1-2B2E-4BD2-9F66-1C2D02F7A29C" codebase="vcp400.cab" width="0" height="0" id="vcp400">
                      </object>
                     </p>
                    </div>
                   
        </div>
    </div>
</body>
</html>
<script type="text/javascript">

   //显示挂失或停用的会员信息
     var pageNum=1;
     var pageSize=8;
          
         $.ajax({
            type:"POST",
            url:"<%:Url.Action("LoadData","LostCard") %>",
            data:"pageSize="+pageSize+"",
            cache:false,
            success:function(html)
            {
    
                $(".showLostOrStop").html(html);
                newPage("首页");
            }
           })
               $.ajax({
            type:"POST",
            url:"<%:Url.Action("Data_Load_maxPage","LostCard") %>",
            data:"pageSize="+pageSize+"",
            cache:false,
            success:function(html)
            {
                $("#maxPage").html(html);
               
            }
        })

        function newPage(sa)
        {
           var CurrentPage= $("#CurrentPage").html();
             var maxPage=$("#maxPage").html();
           
            maxPage=parseInt(maxPage);
            
            
            if(sa=="首页")
            {
                pageNum=1;
               document.getElementById("CurrentPage").innerHTML=pageNum;
            }
            if(sa=="下一页")
            {
                 if(CurrentPage>=maxPage)
                {
                     alert("已是最大页数");
                    return;
                }
                pageNum++;
                document.getElementById("CurrentPage").innerHTML=pageNum;
               
            }
            if(sa=="上一页")
            {
                 if(CurrentPage==1)
            {
                alert("已是最小页数");
                return;
            } 
                pageNum--;
                document.getElementById("CurrentPage").innerHTML=pageNum;
            }
            if(sa=="末页")
            {
                pageNum=maxPage;
                 document.getElementById("CurrentPage").innerHTML=pageNum;
            }
              $.ajax({
                type:"POST",
                url:"<%:Url.Action("newPage","LostCard") %>",
                data:"pageNum="+pageNum+"&pageSize="+pageSize+"",
                cache:false,
                success:function(html)
                {
                $(".showLostOrStop").html(html); 
                }
            })
        }

    //挂失或停用
    function lostCard(o) {
        var memberId = $("#memberId").val();
           $.ajax({
                type:"POST",
                url:"<%:Url.Action("LostCard","LostCard") %>",
                data:"memberId="+memberId+"&selectValue="+o+"",
                cache:false,
                success:function(txt){
                   alert(txt);
                }
            }); 
    }
    //换卡
    function exchangeCard(){
        var memberId = $("#memberId").val();
        if(memberId==null ||memberId==""){
         alert("会员编号不能为空");
         return false;
        }
          $.ajax({
                type:"POST",
                url:"<%:Url.Action("exchangCard","LostCard") %>",
                data:"memberId="+memberId+"",
                cache:false,
                success:function(txt){
                  if(!isNaN(txt)){
                    RfidCardWriteData(txt);
                    Dischange();
                    alert("换卡成功");
                   }
                   else{
                    alert(txt);
                  }
                }
            }); 
    }

     // 写指定块数据
        function RfidCardWriteData(o) {
            var hComm = 0;
            hComm = GetCOM(); 
            nrtn = vcp400.RfidCardWriteData(hComm, 1, 0, "", o, 15);
            if (nrtn = 32) {
                
            }
            else {
                alert('写数据失败.')
            }
            vcp400.ocx_CommClose(hComm);
        }
         function GetCOM() {
            COM = 100;
            Baud =57600;
            
            return vcp400.ocx_commopen(COM, Baud);
        }
         // 退卡	
        function Dischange() {
            var hComm = 0;

            hComm = GetCOM();

            vcp400.Dischange(hComm, 1, 10); 	// 0=不完全退卡,1=完全退卡

            vcp400.ocx_CommClose(hComm);

        }
    //获取选中行信息
    function getSelectInm(o)
    {
     $.ajax({
                type:"POST",
                url:"<%:Url.Action("getSelected","LostCard") %>",
                data:"memberId="+o+"",
                cache:false,
                success:function(txt){
                   var str=txt.toString().split(',');
                    $("#memberId").val(str[0]);
                    $("#point").val(str[1]);
                    $("#IDnumber").val(str[2]);
                    $("#balance").val(str[3]);
                    $("#memberName").val(str[4]);
                }
            }); 
    }
     function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return (r[2]); return null;
    }
     //关闭窗口
    function closeWindows()
    {
        var test = GetQueryString("memberId");
        if (test == null || test == "") {
            window.location.href = "/Loading/Index/?src=/Desktop/Index/";
        }
        else {
            var i = parent.layer.getFrameIndex();
            parent.layer.close(i);
        }
    }
</script>